package net.dreamlu.qa.validator;

import net.dreamlu.qa.model.Question;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * 问题参数校验
 * @author chunmeng.lu
 *
 */
public class QuestionValidator extends Validator {
	
	protected void validate(Controller controller) {
		setShortCircuit(true);
		validateString("question.title", 6, 100, "errorTitle", "标题6~100字！");
		validateString("question.content", 6, 100, "errorTitle", "内容的字数过少, 请详细描述！");
		validateInteger("question.sort_id", 1, 11, "errorSort", "请选择一个分类！");
		validateToken("questionToken", "errorToken", "请不要重复提交！");
	}
	
	protected void handleError(Controller controller) {
		controller.keepModel(Question.class);
		controller.render("/solution/ask.jsp");
	}
}